package com.colors.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author colors
 * @date 2021/1/13 11:39
 */
@RestController
@Slf4j
public class FlowLimitController {

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/testA")
    public String testA() {
        log.info("serverPort:" + serverPort);
        return "-------------test A";
    }

    @GetMapping("/testB")
    public String testB() {
        log.info(Thread.currentThread().getName() +"...testB" );
        return "-------------test B";
    }



    @GetMapping("/testD")
    public String testC(){
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("测试RT");
        return "---testD";
    }

    @GetMapping("/hotkey")
    @SentinelResource(value = "hotkey", blockHandler = "deal_hotkey")
    public String hotKey(@RequestParam(value = "p1", required = false) String p1,
                         @RequestParam(value = "p2", required = false) String p2) {
        return "----hotkey";
    }

    public String deal_hotkey(String p1, String p2, BlockException exception) {
        return "----deal_hotkey";
    }

}
